package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.ArchiveCancel;
import com.amsp.oa.oademo.mapper.ArchiveCancelMapper;
import com.amsp.oa.oademo.service.IArchiveCancelService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class ArchiveCancelServiceImpl extends ServiceImpl<ArchiveCancelMapper, ArchiveCancel>
        implements IArchiveCancelService {

    @Override
    public IPage<ArchiveCancel> getPage(Integer page, Integer size, String employeeName, String employeeNumber) {
        LambdaQueryWrapper<ArchiveCancel> queryWrapper = new LambdaQueryWrapper<>();

        // 添加查询条件
        if (StringUtils.isNotBlank(employeeName)) {
            queryWrapper.like(ArchiveCancel::getEmployeeName, employeeName);
        }

        if (StringUtils.isNotBlank(employeeNumber)) {
            queryWrapper.like(ArchiveCancel::getEmployeeNumber, employeeNumber);
        }

        // 按创建时间倒序排序
        queryWrapper.orderByDesc(ArchiveCancel::getCreateTime);

        // 创建分页对象
        Page<ArchiveCancel> pageParam = new Page<>(page, size);

        // 执行分页查询
        return this.page(pageParam, queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdateBatchTransactional(List<ArchiveCancel> records) {
        return super.saveOrUpdateBatch(records);
    }
}